package cn.edu.nju.software.zp13.assignment6.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class FileReadWriteUtil {
	  public static void write(String path, String content, String encoding)  
	            throws IOException {  
	        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(  
	                new FileOutputStream(path), encoding));  
	        writer.write(content);  
	        writer.close();  
	    }  
	  
	    public static String read(String path, String encoding) throws IOException {  
	        BufferedReader reader = new BufferedReader(new InputStreamReader(  
	                new FileInputStream(path), encoding));  
	        StringBuffer sb=new StringBuffer();
	        String line = null;  
	        while ((line = reader.readLine()) != null) {  
	            sb.append(line+System.getProperty("line.seperator"));  
	        }  
	        reader.close();  
	        return sb.toString();  
	    }  
}
